package com.example.algorithm.greedy;

/**
 * @author : zhy
 * @since : 2022/8/26
 * 摆动序列
 */
public class MoveList {

    public int wiggleMaxLength(int[] nums) {
        int len=nums.length;
        if(len<=1){
            return len;
        }
        int count=1;
        int curDiff=0;
        int perDiff=0;
        for(int i=1;i<len;i++)
        {
            curDiff=nums[i]-nums[i-1];
            if((curDiff>0&&perDiff<=0)||(curDiff<0&&perDiff>=0))
            {
                count++;
                perDiff=curDiff;
            }
        }
        return count;
    }

    public static void main(String[] args) {

    }
}
